package kyssion.leetcode.num51_100;

public class code66_加一 {
    public int[] plusOne(int[] digits) {
        int index = digits.length - 1;
        int number = 1;
        while (index >= 0) {
            digits[index] = digits[index] + number;
            if (digits[index] >= 10) {
                number = 1;
                digits[index] = digits[index] - 10;
            }else{
                break;
            }
            index--;
        }

        if (index < 0) {
            int[] i = new int[digits.length+1];
            i[0]=1;
            return i;
        }
        return digits;
    }
}
